package com.sline.OtherClass;

import java.util.Calendar;

public class Demo_Calendar {
    public static void main(String[] args) {
        // demo1();

        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR, 1);
        c.set(2000, 9,9);

        System.out.println(c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日" + getWeek(c.get(Calendar.DAY_OF_WEEK)));
    }

    private static void demo1() {
        Calendar c = Calendar.getInstance();
        System.out.println(c);
        System.out.println(c.get(Calendar.YEAR));           // 获取年份
        System.out.println(c.get(Calendar.MONTH));          // 获取月份, 月份从0开始编号, 真正的月份需要+1
        System.out.println(c.get(Calendar.DAY_OF_MONTH));   // 获取日期中的天
        System.out.println(c.get(Calendar.DAY_OF_WEEK));    // 获取星期几, 星期天为第一天

        System.out.println(c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日" + getWeek(c.get(Calendar.DAY_OF_WEEK)));
    }

    public static String getWeek(int week) {
        String[] arr = {"", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

        String weekStr = "";
        if (week < arr.length) {
            weekStr = arr[week];
        }

        return weekStr;
    }
}
